/*action create by pionner code builder*/
package com.pioneer.app.sms.jiaotong;

import java.io.Serializable;

import org.hibernate.Transaction;

import java.util.List;


import com.opensymphony.xwork2.Action;

import java.io.Serializable;

public class CarInfoAction implements Action, Serializable {

	// key
	private java.lang.Integer id;

	private java.lang.Integer[] ids;
	private CarInfo carinfo;
	private java.lang.String carNo;
	private java.lang.String carOwner;
	private java.lang.String ownerNo;
	private java.lang.String mobile;
	private java.lang.String address;
	private java.lang.String email;
	private List objects=null;
	private String condition=null;
	private String fromTree=null;
	/** 默认构造方法 */
	public CarInfoAction(){
	}
	/** full constructor */
	public CarInfoAction(java.lang.String carNo,java.lang.String carOwner,java.lang.String ownerNo,java.lang.String mobile,java.lang.String address,java.lang.String emai){
		this.carNo=carNo;
		this.carOwner=carOwner;
		this.ownerNo=ownerNo;
		this.mobile=mobile;
		this.address=address;
		this.email=email;

	}
	public void setId(java.lang.Integer id){
		this.id=id;
	}
	public java.lang.Integer getId(){
		return id;
	}

	public void setIds(java.lang.Integer[] ids){
		this.ids=ids;
	}
	public java.lang.Integer[] getIds(){
		return ids;
	}

	public void setCarInfo(CarInfo carinfo){
		this.carinfo=carinfo;
	}
	public CarInfo getCarInfo(){
		return carinfo;
	}

	public void setCarNo(java.lang.String carNo){
		this.carNo=carNo;
	}
	public java.lang.String getCarNo(){
		return carNo;
	}

	public void setCarOwner(java.lang.String carOwner){
		this.carOwner=carOwner;
	}
	public java.lang.String getCarOwner(){
		return carOwner;
	}

	public void setOwnerNo(java.lang.String ownerNo){
		this.ownerNo=ownerNo;
	}
	public java.lang.String getOwnerNo(){
		return ownerNo;
	}

	public void setMobile(java.lang.String mobile){
		this.mobile=mobile;
	}
	public java.lang.String getMobile(){
		return mobile;
	}

	public void setAddress(java.lang.String address){
		this.address=address;
	}
	public java.lang.String getAddress(){
		return address;
	}

	public void setEmail(java.lang.String email){
		this.email=email;
	}
	public java.lang.String getEmail(){
		return email;
	}

	public List getObjects() {
		return objects;
	}

	public void setObjects(List objects) {
		this.objects = objects;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public String execute() throws Exception {
		return "SUCESS";
	}

	public String doList(){
		CarInfoDAO dao=new CarInfoDAO();
		this.objects=dao.findByCondition(condition);
		return "list";
	}

	public String doAdd(){
		return "add";
	}

	public String doEdit(){
		CarInfoDAO dao=new CarInfoDAO();
		this.carinfo=dao.findById(id);
		this.sedObj();;
		return "edit";
	}

	public String doSave(){
		Transaction tx=null;
		try {
			this.buildObj();
			CarInfoDAO dao=new CarInfoDAO();
			tx=dao.getSession().beginTransaction();
			if(null==this.carinfo.getId()){
//			insert a new object
			//gave the object id by database 
				dao.add(carinfo);
			}else{
//			update the object
				dao.getSession().clear();
				dao.update(carinfo);
			}
			tx.commit();
		} catch (Exception e) {
			tx.rollback();
			e.printStackTrace();
			return "error";
		}
		return "list";
	}

	public String doDetail(){
			CarInfoDAO dao=new CarInfoDAO();
		this.carinfo=dao.findById(id);
		this.sedObj();;
		if(null!=fromTree){;
			return "detail";
		}else{
			return "list";
		}
	}

	public String doDelete(){
		try{
			CarInfoDAO dao=new CarInfoDAO();
			dao.deleteObjs(ids);
			return "list";
		}catch(Exception e){
			return "error";
		}
	}

	private void buildObj(){
		this.carinfo=new CarInfo();
		this.carinfo.setId(this.id);
		this.carinfo.setCarNo(this.carNo);
		this.carinfo.setCarOwner(this.carOwner);
		this.carinfo.setOwnerNo(this.ownerNo);
		this.carinfo.setMobile(this.mobile);
		this.carinfo.setAddress(this.address);
		this.carinfo.setEmail(this.email);
	}
	private void sedObj(){

		if(null!=this.carinfo){
			this.id=this.carinfo.getId();
			this.carNo=this.carinfo.getCarNo();
			this.carOwner=this.carinfo.getCarOwner();
			this.ownerNo=this.carinfo.getOwnerNo();
			this.mobile=this.carinfo.getMobile();
			this.address=this.carinfo.getAddress();
			this.email=this.carinfo.getEmail();

		}
	}
}